package com.woniu.woniuk16.controller;


import com.woniu.woniuk16.dto.ClassUserDto;
import com.woniu.woniuk16.dto.ClassUsersDto;
import com.woniu.woniuk16.exception.stu.CourceExceprion;
import com.woniu.woniuk16.exception.stu.StudentException;
import com.woniu.woniuk16.model.Result;
import com.woniu.woniuk16.param.GetByClass;
import com.woniu.woniuk16.param.PlanCourceParam;
import com.woniu.woniuk16.service.WoniuClassUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tiangle
 * @since 2021-12-16
 */
@RestController
@RequestMapping("/woniuClassUser")
public class WoniuClassUserController {
    @Autowired
    private WoniuClassUserService woniuClassUserService;
    @PostMapping("/plan")
    public Result planCource(@RequestBody PlanCourceParam planCourceParam) throws StudentException, CourceExceprion, ParseException {
        boolean b = woniuClassUserService.planCource(planCourceParam);
        if (b)
        return Result.getInstance(null);
        throw new StudentException("排课失败");
    }

    @GetMapping("/all")
    public Result getAll(){
        List<ClassUserDto> getcuds = woniuClassUserService.getcuds();
        return Result.getInstance(getcuds);
    }

    @PostMapping("/like")
    public Result getByClass(@RequestBody GetByClass getByClass) throws CourceExceprion {
        ClassUsersDto classUsersDto = woniuClassUserService.getcudsByClass(getByClass);
        return Result.getInstance(classUsersDto);
    }
}

